<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;
class AdminUserscorerecord extends Model
{
    use SoftDelete;
     protected $deleteTime = "delete_time";
    // 获取列表
    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        
               //按openid查找
               if ($openid = input("openid")) {
                   $where[] = ["openid", "like", "%" . $openid . "%"];
               }
        $list = self::order('id','desc')->where($where)->paginate($limit);
        return ['code'=>0,'data'=>$list->items(),'extend'=>['count' => $list->total(), 'limit' => $limit]];
    }
    public static function addandreturn($data)
    {
        //echo($data['openid']);
       // echo($data['score']);
       $today = date("Y-m-d");
       $startday=date("Y-m-d").' 0:00:00';
       $today_end = $today.' 23:59:59';
        $openid=$data['openid'];
        if($data['score']>0){
            $sums=self::where("openid",$openid)->where('create_time','between',[$startday,$today_end])->sum('score');
           //echo($sums.'|');
            if($sums>=5000)
            {
                //echo("大于5000");
                return 203;
            }
            self::create($data);
            
            //echo($startday.'|');
            //echo($today_end);
            return 200;
        }
        //$totalscore=
    }
}
